package com.itheima.TestBreeder;


import com.itheima.Test5.A;

public abstract class Animal {
    private int age;

    public Animal() {
    }

    public Animal(int age) {
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void drink(){
        System.out.println("喝水");
    }

    public abstract void eat();

    @Override
    public boolean equals(Object o) {
        /*if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Animal animal = (Animal) o;

        return age == animal.age;*/

        //如果当前对象与比较的对象地址值相同，则返回true;
        if (this == o)return true;
        //如果需比较的对象是null,或者需比较的对象的类与本对象的类不是同一个，则返回false;
        if (o==null || o.getClass() != this.getClass()) return false;
        //如果上述不满足：
//        将获取的对象向下转型到比较的对象类型：
        Animal animal = (Animal) o;

        return animal.age==this.age;
    }


}
